package client.connect;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;



public class PanelUsers extends JPanel {

	static String[] names = { "Arlo", "Cosmo", "Elmo", "Hugo", "Jethro",
			"Laszlo", "Milo", "Nemo", "Otto", "Ringo", "Rocco", "Rollo" };
	
	JList list= null;
	DefaultListModel <String>listModel = new DefaultListModel<String>();
	
	public PanelUsers(FrameConnect frame) {
		
		setPreferredSize(new Dimension(400, 230));
		setBackground(Color.WHITE);
		setBorder(BorderFactory.createLineBorder(Color.PINK));
		setBorder(BorderFactory.createLoweredBevelBorder());

		//showUsers();
		list = new JList(listModel);
		this.add(list);
		setVisible(true);
		
		
	}
	
	public void showUsers(List <String>  membres) {
	//	this.remove(list);
		System.out.println("list: "+ membres);
		
	
	this.UpdateList(membres);
		
	this.revalidate();
		 

	}
	
	public ArrayList<String>   getMemberSelected() {
		int [] selection = this.list.getSelectedIndices();
		ArrayList<String>  listMembre= new ArrayList<String>();
		for (int i : selection)
		{
			listMembre.add(this.listModel.get(i));
		}
		
		return listMembre;
	}
	
	

	
	private void UpdateList(List<String> membres) {
		
		
		for ( String s : membres)
		{
			if (!listModel.contains(s))
			{
				listModel.addElement(s);
			}
		}
		

		
		
	}

	static String  afftab( String[] userNames)
	{
		String str="";
		for (String s : userNames )
		{
			str += s+"; ";
		}
		return str;
	}
}
